home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / setConstraintRestPosition.me < prev    next >
Encoding:
Text File  |  2003-07-17  |  3.9 KB  |  113 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  Dec, 2002
  22. //
  23. //<doc>
  24. //<name setConstraintRestPosition>
  25. //<owner "Alias|Wavefront Unsupported">
  26. //
  27. //<synopsis>
  28. //        setConstraintRestPosition
  29. //
  30. //<returns>
  31. //        None
  32. //
  33. //<description>
  34. //      Script for setting the rest position of a constrained object.
  35. //
  36. //<examples>
  37. //        The rest position is where a constrained object goes to when
  38. //      the constraint is disabled (i.e. all weights equal zero).
  39. //
  40. //      Say you have a cup constrained to a skeleton. At frame 10, you
  41. //      want the skeleton to set the object on the table, where it will remain.
  42. //      Go to frame 10, select the cup and call this method to set the
  43. //      rest position.
  44. //
  45. //      The constraint can now be disabled by setting its weight to 0,
  46. //      and the cup will stay at its rest position.
  47. //
  48. //</doc>
  49. /////////////////////////////////////////////////////////////////////////
  50.  
  51. global proc setConstraintRestPosition()
  52. {
  53.     string $sels[] = `ls -sl`;
  54.  
  55.     int $counter = 0;
  56.     string $constrainAttr = ".rotate";
  57.     string $restAttr = ".restRotate";
  58.  
  59.     for ($constrainedObj in $sels) {
  60.         // Find the constraint
  61.         //
  62.         string $constraint;
  63.         string $p1 = `pointConstraint -q $constrainedObj`;
  64.         string $a1 = `aimConstraint -q $constrainedObj`;
  65.         string $o1 = `orientConstraint -q $constrainedObj`;
  66.         string $s1 = `scaleConstraint -q $constrainedObj`;
  67.         string $t1 = `tangentConstraint -q $constrainedObj`;
  68.         string $n1 = `normalConstraint -q $constrainedObj`;        
  69.         string $par = `parentConstraint -q $constrainedObj`;
  70.         if (size($p1)) {
  71.             $constraint = $p1;
  72.             $constrainAttr = ".translate";
  73.             $restAttr = ".restTranslate";
  74.         } else if (size($a1)) {
  75.             $constraint = $a1;
  76.         } else if  (size($o1)) {
  77.             $constraint = $o1;            
  78.         } else if  (size($s1)) {
  79.             $constrainAttr = ".scale";
  80.             $restAttr = ".restScale";
  81.             $constraint = $s1;
  82.         } else if  (size($t1)) {
  83.             $constraint = $t1;            
  84.         } else if  (size($n1)) {
  85.             $constraint = $n1;
  86.         }
  87.         
  88.         if (size($constraint)) {
  89.             float $currVal[] = `getAttr ($constrainedObj+$constrainAttr)`;
  90.             string $cmd = ("setAttr " + $constraint+$restAttr + " ");
  91.             $cmd += ($currVal[0] + " " + $currVal[1] + " " + $currVal[2]);
  92.             evalEcho $cmd;
  93.             setAttr ($constrainedObj+$constrainAttr) $currVal[0] $currVal[1] $currVal[2];
  94.             $counter++;
  95.         } else if (size($par)) {
  96.             float $currPos[] = `getAttr ($constrainedObj+".translate")`;
  97.             float $currRot[] = `getAttr ($constrainedObj+".rotate")`;
  98.             string $cmd = ("setAttr "+$par+".restTranslate ");
  99.             $cmd += ($currPos[0] + " " + $currPos[1] + " " + $currPos[2]);
  100.             evalEcho $cmd;            
  101.             string $cmd = ("setAttr "+$par+".restRotate ");
  102.             $cmd += ($currRot[0] + " " + $currRot[1] + " " + $currRot[2]);
  103.             evalEcho $cmd;
  104.             setAttr ($constrainedObj+".translate") $currPos[0] $currPos[1] $currPos[2];
  105.             setAttr ($constrainedObj+".rotate") $currRot[0] $currRot[1] $currRot[2];
  106.             $counter++;
  107.         }
  108.     }
  109.     if (0 == $counter) {
  110.         error("A constrained object must be selected.");
  111.     }
  112. }
  113.